package com.qf.servlet;

import com.qf.pojo.DtsBrand;
import com.qf.service.DtsAdminService;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsCategoryService;
import com.qf.util.ResponseUtil;
import com.qf.vo.CatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Ypl
 * @version V1.0
 * @Project September-mavens
 * @Package com.qf.servlet
 * @Description:
 * @Date 2022/10/22 10:30
 */
@RestController
@RequestMapping("/admin/brand")
public class AdminBrandController {

    @Autowired
    DtsBrandService dtsBrandService;

    @Autowired
    DtsAdminService dtsAdminService;

    @Autowired
    DtsCategoryService dtsCategoryService;
    /**
     * 品牌制造商查询
     *  业务分析：
     * 1.如果登录的用户是品牌制造商，那么他只能看到自己的品牌制造商列表，查询的是自己的品牌
     * 2.如果超级管理员要删除品牌制造商，那么也要去删除dts_goods里面的品牌制造商所对应的商品，商品属性，商品规格，等等都要删除
     * 3.如果逻辑删除了品牌制造商，那么阿里云上的相关的也要删除，是直接删除
     */
    @GetMapping("list")
    public Object list(@RequestParam(value = "page",defaultValue = "1") Integer page,
                       @RequestParam(value = "limit",defaultValue = "20")Integer limit,
                       @RequestParam(value = "sort",defaultValue = "add_time")String sort,
                       @RequestParam(value = "order",defaultValue = "desc") String order,
                       Integer id,String name){

        Map<String,Object> data = dtsBrandService.findByPage(page,limit,order,sort,id,name);

        return ResponseUtil.ok(data);
    }

    /**
     * 商品和管理员列表
     */
    @RequestMapping("/catAndAdmin")
    public Object catAndAdmin(){

        Map<String,Object> data = new HashMap<>();

        List<Map<String,Object>> adminList = dtsAdminService.findAll();
        //管理员列表
        data.put("adminList", adminList);

        List<CatVo> categoryList = dtsCategoryService.findList();
        //商品类目列表
        data.put("categoryList", categoryList);

        return ResponseUtil.ok(data);

    }

    /**
     * 品牌制造商和添加
     */
    @PostMapping("/create")
    public Object insert(@RequestBody DtsBrand dtsBrand){
        dtsBrandService.insert(dtsBrand);
        return ResponseUtil.ok(dtsBrand);
    }
    /**
     * 品牌制造商更新
     */
    @PostMapping("/update")
    public Object update(@RequestBody DtsBrand dtsBrand){
        dtsBrandService.update(dtsBrand);
        return ResponseUtil.ok(dtsBrand);
    }
    /**
     * 品牌制造商
     */
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsBrand dtsBrand){
        dtsBrandService.delete(dtsBrand);
        return ResponseUtil.ok();
    }
}
